<?php
// +----------------------------------------------------------------------
// | zhanshop-marketing / TestPostBackAd.php    [ 2024/12/26 09:20 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2024 zhangqiquan All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangqiquan <768617998@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\console;

use app\provider\AdEventUploadProvider;
use zhanshop\App;
use zhanshop\console\Command;
use zhanshop\console\Input;
use zhanshop\console\Output;

class TestPostBackAd extends Command
{
    public function configure()
    {
        $this->useDatabase()->setTitle("广告回传")->setDescription('测试广告回传');
    }

    public function execute(Input $input, Output $output)
    {
        $app = $input->input("app", "请输入app");
        $type = $input->input("type", "请输入匹配类型, 可选值(oaid,imei,android_id,mac,idfa,ipv4,ipv6,iddi)");
        $val = $input->input("val", "请输入匹配的值");
        $matchItem = ["oaid" => "", "imei" => "", "android_id" => "", "mac" => "", "idfa" => "", "iddi" => "", 'ipv4' => '127.0.0.1', 'ipv6' => '::', 'ua' => '', 'unit_type' => ''];
        $matchItem[$type] = $val;
        // 激活
        $result = App::make(AdEventUploadProvider::class)->upload($app, 'all', 'activate', $matchItem);
        list($aduid, $platform) = $result;
        if($aduid == false){
            App::error()->setError("没有相关的匹配项");
        }
        $record = App::database()->table("ad_upload")->where(['app' => $app, 'uuid' => "0", 'upload_event' => 'activate'])->order('id desc')->find();
        // 注册
        $platform = $record['platform'];
        $result = App::make(AdEventUploadProvider::class)->$platform($app, "register", $record['mate_type'], ['uuid' => $record['uuid']], $record);
        // 下单
        $result = App::make(AdEventUploadProvider::class)->$platform($app, "order", $record['mate_type'], ['uuid' => $record['uuid']], $record);
        // 付费
        $result = App::make(AdEventUploadProvider::class)->$platform($app, "pay", $record['mate_type'], ['uuid' => $record['uuid']], $record);
    }
}